package com.xysd.examproject.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.jph.takephoto.app.TakePhotoFragment;
import com.jph.takephoto.model.TResult;
import com.xysd.examproject.R;
import com.xysd.examproject.util.ToastUtil;
import com.xysd.examproject.util.http.HttpCallBack;
import com.xysd.examproject.util.http.HttpUtil;
import com.xysd.examproject.widget.WIFIDialog;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * Created by donghui on 2017/5/26.
 */

@ContentView(R.layout.fragment_second)
public class SecondFragment extends TakePhotoFragment implements View.OnClickListener {

    @ViewInject(R.id.http_btn)
    private Button http_btn;
    @ViewInject(R.id.wifi_btn)
    private Button wifi_btn;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return x.view().inject(this, inflater, container);//绑定fragment注解
    }

    @Override
    public void onResume() {
        super.onResume();
        ToastUtil.show("22221111112223333");
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        init();
    }

    private void init() {
        http_btn.setOnClickListener(this);
        wifi_btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.http_btn:
                getData();
                break;
            case R.id.wifi_btn:
                new WIFIDialog(getActivity()).show();
                break;

            default:

                break;
        }
    }

    private void getData() {
        HttpUtil.getTeacherDetails("43", new HttpCallBack() {
            @Override
            public void onSuccess(String result) {
                Log.i("getTeacherDetails",result);
            }

            @Override
            public void onFailure(String error) {
                Log.e("getTeacherDetails",error);
            }
        });
    }

    @Override
    public void takeSuccess(TResult result) {
        Log.i("takePhoto","takeSuccess：" + result.getImage().getCompressPath());
    }
    @Override
    public void takeFail(TResult result,String msg) {
        Log.i("takePhoto", "takeFail:" + msg);
    }
    @Override
    public void takeCancel() {
        Log.i("takePhoto", getResources().getString(com.jph.takephoto.R.string.msg_operation_canceled));
    }
}
